<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;
use Think\Controller;
class IndexController extends BaseController {
    public function index(){    	
    	$this->init();
		$this->display();
    }

    // 设置logo页面
    public function setLogo(){
    	$this->init();
		$this->display();
    }

    //设置标题
    public function setTitle(){
    	$this->init();
		$indexweb=M('indexweb');
    	if(isset($_POST['title'])){
    		$data['title']=I('post.title');
    		$indexweb->where('id=1')->save($data);
    	}
    	$data = $indexweb->where('id=1')->find();
    	$this->assign('webinfo',$data);
    	// var_dump($data['title']);
		$this->display();
    }

    //设置轮播
    public function setCarousel(){
    	$this->init();
		$indexweb=M('indexweb');
		$data=$indexweb->select();
		$this->assign('silde',json_decode($data[0]['index_silde']));
		$this->display();
    }

    // 设置轮播
    public function uploadCarousel(){
  		$config = array(
		    'maxSize'    =>    5145728,
		    'savePath'   =>    '/carousel/',
		    'saveName'   =>    array('uniqid',''),
		    'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
		    'autoSub'    =>    false,
		    'subName'    =>    array('date','Ymd'),
		);
		$upload = new \Think\Upload($config);
  		$carousel_img_list=dealFiles($_FILES['files']);
  		$imgarr = array();
  		foreach ($carousel_img_list as $key => $value) {
			if(!empty($value['tmp_name'])){
				$info=$upload->uploadOne($value);
				if(!$info){
					$this->error($upload->getError());
				}else{
					$imgarr[] = "Uploads".$info['savepath'].$info['savename'];
				}
			}else{
				$info=true;
			}
  		}
		$data['index_silde']=json_encode($imgarr);
		$indexweb=M('indexweb');
		if($indexweb->where('id=1')->save($data)){
			$this->success("设置成功",U("Index/setCarousel"));
		}else{
			$this->error('设置失败');
		}

	}

    // 上传logo
    public function uploadLogo(){
    	$config = array(
		    'maxSize'    =>    3145728,
		    'savePath'   =>    '/logo/',
		    'saveName'   =>    array('uniqid',''),
		    'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),
		    'autoSub'    =>    false,
		    'subName'    =>    array('date','Ymd'),
		    'replace'    =>    true,
		);
		$upload = new \Think\Upload($config);
		$upload->saveName = 'logo';
		if(!empty($_FILES['logo_img']['tmp_name'])){
			$info   = $upload->uploadOne($_FILES['logo_img']);
		}else{
			$info=true;
		}
		if(!$info){
			$this->error($upload->getError());
		}else{
			$indexweb=M('indexweb');
			$data['logo_img']="";
			$indexweb->where('id=1')->save($data);
			$data['logo_img']="Uploads".$info['savepath']."logo.".$info['ext'];
			if($indexweb->where('id=1')->save($data)){
				$this->success("设置成功",U("Index/setLogo"));
			}else{
				$this->error('设置失败');
			}
		}
    }
}